home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / LGP250S1.ZIP / src / libgplus.5 / libgplus / proto-ki / genclass.ext < prev    next >
Text File  |  1991-06-28  |  3KB  |  113 lines

  1. #!/bin/csh
  2.  
  3. # shell script for generating classes from prototypes
  4. #
  5. # usage: genclass protodir cdir extension type {ref | val} [type {ref | val}] ...  proto 
  6. #
  7.  
  8. set PROGRAM_NAME=$0
  9. set USAGE="Usage: ${PROGRAM_NAME} '<Proto dir> <C dir> <C file extension> <type> {ref | val} [<type> {ref | val}] ...  <prototype>'";
  10.  
  11. # there are at least 6 parameters, plus the program name (total of seven)
  12. if (($#argv < 6) || ($#argv % 2) > 0) then
  13.   echo "${PROGRAM_NAME}: invalid parameter count";
  14.   echo "${USAGE}";
  15.   exit 1;
  16. endif
  17.  
  18. set PWD=`pwd`/
  19.  
  20. # get the prototype directory, the C directory and the C file extension (.h or .cc)
  21. # from the argument list
  22. set PROTODIR = $1;     shift;
  23. set OUTDIR = $1;     shift;
  24. set EXTNSN = $1;     shift;
  25.  
  26. if ($PROTODIR !~ */) then
  27.   set PROTODIR = $PROTODIR/
  28. endif
  29. if ($OUTDIR !~ */) then
  30.   set OUTDIR = $OUTDIR/
  31. endif
  32.  
  33. set FILE_NAME=;
  34. set CLASS_NAME=;
  35. set TYPES=;
  36. set VALS=;
  37.  
  38. # loop through the parameters, pulling <type> <reference type> pairs off the 
  39. # argument list.
  40.  
  41. while ( $#argv > 2 )
  42.   set TYPES = (${TYPES} $1)
  43.   set VALS = (${VALS} $2)
  44.   set FILE_NAME = "${FILE_NAME}$1."
  45.   set CLASS_NAME = "${CLASS_NAME}$1"
  46.  
  47.   if (($2 != "ref") && ($2 != "val")) then
  48.     echo "${PROGRAM_NAME}: invalid reference type" ; 
  49.     echo ${USAGE} ; 
  50.     exit 1;
  51.     endif
  52.  
  53.   shift; 
  54.   shift;
  55. end
  56.  
  57. set CLASS = $1
  58.  
  59. set FILE_NAME = "${FILE_NAME}${CLASS}.${EXTNSN}"
  60. set CLASS_NAME = "${CLASS_NAME}${CLASS}"
  61. set HSRC      = "$CLASS.hP"
  62. set SRC       = "$CLASS.${EXTNSN}P"
  63. set OUT       = "$OUTDIR$FILE_NAME"
  64.  
  65. if ( (-f $PWD$SRC) && (-r $PWD$SRC) && (-f $PWD$HSRC) ) then
  66.   set PSRC = $PWD$SRC
  67.   set HSRC = $PWD$HSRC
  68. else if ( (-f $PROTODIR$SRC) && (-r $PROTODIR$SRC) && (-f $PROTODIR$HSRC) ) then
  69.   set PSRC = $PROTODIR$SRC
  70.   set HSRC = $PROTODIR$HSRC
  71. else 
  72.   echo "${PROGRAM_NAME}: $SRC: no such file"; 
  73.   exit 1;
  74. endif
  75.  
  76. set SEARCH_STRING = (generic class $CLASS\\\[.\*\\\])
  77.  
  78. set SED_SCRIPT = /tmp/genclass.$$
  79.  
  80. # this is so we can handle unreformed files from the distribution
  81. if (1) then
  82.   set TYPE_LIST = T
  83.   if ( $#TYPES == 2 ) set TYPE_LIST = (${TYPE_LIST} C)
  84. else
  85.   # get TYPE_LIST somehow... ???
  86.   set TEMP = "`grep $SEARCH_STRING $HSRC`" 
  87.   set TYPE_LIST=(`expr $TEMP : \[^\\\[\]\*\\\[\(.*\)\\\].\* | tr ',' ' '`);
  88.   unset TEMP
  89.   echo "s/$SEARCH_STRING/class $CLASS_NAME/g" >> SED_SCRIPT
  90. endif
  91.  
  92. set DUMMY=0
  93. while ( $DUMMY < $#TYPES )
  94.   @ DUMMY++
  95.   set PREAMBLE = 's/<';
  96.   set MIDDLE = '>/';
  97.   set POSTAMBLE = '/g';
  98.   echo ${PREAMBLE}${TYPE_LIST[$DUMMY]}${MIDDLE}${TYPES[$DUMMY]}${POSTAMBLE} >>$SED_SCRIPT
  99.  
  100.   set MIDDLE = "&$MIDDLE"
  101.   if ($VALS[$DUMMY] == "ref") set POSTAMBLE = "\&$POSTAMBLE";
  102.  
  103.   echo ${PREAMBLE}${TYPE_LIST[$DUMMY]}${MIDDLE}${TYPES[$DUMMY]}${POSTAMBLE} >>$SED_SCRIPT
  104. end
  105.  
  106. sed -f $SED_SCRIPT < $PSRC > $OUT 
  107.  
  108. rm -f $SED_SCRIPT
  109.  
  110.  
  111.  
  112.  
  113.